#include"../source/server.hpp"

void OnClosed(const PtrConnection& conn)
{
    DBG_LOG("CLOSE CONNECTION:%p",conn.get());
}

void OnConnected(const PtrConnection& conn)
{
    DBG_LOG("NEW CONNECTION:%p",conn.get());
}

void OnMessage(const PtrConnection& conn,Buffer* buf)
{
    DBG_LOG("%s",buf->ReadPosition());
    buf->MoveReadOffset(buf->ReadAbleSize());

    std::string str = "i loooooove ghx";
    conn->Send(str.c_str(),str.size());
    conn->Shutdown();
}

int main()
{
    TcpServer server(9658);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);
    server.SetClosedCallback(OnClosed);
    server.SetConnectedCallback(OnClosed);
    server.SetMessageCallback(OnMessage);

    server.Start();

    return 0;
}